// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:flutterdemo/components/img.dart';
import '../../common/calc.dart';

class ShopCart extends StatefulWidget {
  ShopCart({Key? key}) : super(key: key);

  @override
  _ShopCartState createState() => _ShopCartState();
}

class _ShopCartState extends State<ShopCart> {
  // 热门推荐
  Widget _recommendW(constraints) {
    List<Widget> arr = [];
    for (int i = 0; i < 30; i++) {
      if (i % 2 == 0) {
        arr.add(_recommendItem(constraints));
        arr.add(SizedBox(width: constraints.maxWidth * 0.04));
      } else {
        arr.add(_recommendItem(constraints));
      }
    }
    return Wrap(children: arr);
  }

  // 热门推荐每列
  Widget _recommendItem(constraints) {
    double itemWidth = constraints.maxWidth * 0.48;
    return Column(
      children: [
        Ink(
          decoration: BoxDecoration(
            color: Color.fromRGBO(255, 255, 255, 1),
            // borderRadius: BorderRadius.circular(Calc.width(20))
          ),
          child: InkWell(
          onTap: () {
            Navigator.pushNamed(context, "shopInfo");
          },
          child: Container(
            width: itemWidth,
            // margin: EdgeInsets.fromLTRB(0, 0, 0, constraints.maxWidth * 0.04),
            decoration: BoxDecoration(
                border: Border.all(
                  color: Color.fromRGBO(0, 0, 0, 0),
                  width: 1,
                )),
            padding: EdgeInsets.all(Calc.width(10)),
            child: Column(
              children: [
                Container(
                    height: itemWidth * 0.8,
                    child: Img(
                        "http://t13.baidu.com/it/u=4087564718,3919036078&fm=224&app=112&f=JPEG?w=500&h=494")),
                Padding(
                  padding: EdgeInsets.fromLTRB(Calc.width(10.0),
                      Calc.width(10.0), Calc.width(10.0), Calc.width(10.0)),
                  child: Text(
                    "豪华大推拉",
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        color: Colors.black54,
                        fontSize: constraints.maxWidth * 0.045),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(Calc.width(10.0),
                      Calc.width(5.0), Calc.width(10.0), Calc.width(5.0)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "￥188",
                        style: TextStyle(
                            color: Colors.red,
                            fontSize: constraints.maxWidth * 0.05),
                      ),
                      Text(
                        "￥188",
                        style: TextStyle(
                            decoration: TextDecoration.lineThrough,
                            fontSize: constraints.maxWidth * 0.05),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
        ),
        
        SizedBox(height: constraints.maxWidth * 0.04,)
      ],
    );
  }

  @override
  Widget build(context) {
    Calc.init(context);
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        return _recommendW(constraints);
      },
    );
  }
}
